﻿package mortal.game.view.copy.expCopy
{
    import Message.Game.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class ExpCopyIcon extends ActionBaseIcon
    {
        private static var _instance:ExpCopyIcon;

        public function ExpCopyIcon()
        {
            super(ResFileConst.ExpCopyIcon);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.addListener();
            this.checkCanEnterNum();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.removeLister();
            super.disposeImpl(param1);
            return;
        }// end function

        private function addListener(param1:Object = null) : void
        {
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.checkCanEnterNum);
            NetDispatcher.addCmdListener(ServerCommand.ExpCopyInfoGet, this.checkCanEnterNum);
            NetDispatcher.addCmdListener(ServerCommand.BackpackAllDataGet, this.checkCanEnterNum);
            return;
        }// end function

        private function removeLister() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.checkCanEnterNum);
            NetDispatcher.removeCmdListener(ServerCommand.ExpCopyInfoGet, this.checkCanEnterNum);
            NetDispatcher.removeCmdListener(ServerCommand.BackpackAllDataGet, this.checkCanEnterNum);
            return;
        }// end function

        private function checkCanEnterNum(param1:Object = null) : void
        {
            var _loc_4:int = 0;
            var _loc_2:* = ClockManager.instance.serverOpenDateNum;
            var _loc_3:* = Cache.instance.copy.expCopy.getExpCopyInfoByDay(_loc_2);
            if (_loc_3 == null || _loc_3.enterTimes < 6)
            {
                _loc_4 = Cache.instance.copy.expCopy.canEnterCopyNum;
                if (_loc_4 > 0)
                {
                    setIconTxt(_loc_4.toString());
                }
                else
                {
                    setIconTxt("");
                }
            }
            else
            {
                setIconTxt("");
                this.removeLister();
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ExpCopyEnterNumUpdate, _loc_4));
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ExpCopyModuleOpen, null));
            return;
        }// end function

        public static function get instance() : ExpCopyIcon
        {
            if (!_instance)
            {
                _instance = new ExpCopyIcon;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
